
package TUILayer;
import java.util.Scanner;
import java.util.ArrayList;
import ControlLayer.StaffCTR;
import ModelLayer.*;


public class StaffContainerUI
{
    private StaffCTR sctr;
    /**
     * Constructor for objects of class StaffContainerUI
     */
    public StaffContainerUI()
    {
        sctr = new StaffCTR();
    }
    /**
     * Menu Section
     * 
     * start(), executes the menu.
     * staffMenu(), is a selection method for the user menu.
     * writestaffMenu(), is a visual interpretation of the user menu for the staff section.
     */
    public void start()
    {
        staffMenu();
    }
    public void staffMenu()
    {
        boolean exit = false;
        while(!exit)
        {
            int choise = writeStaffMenu();
            if(choise == 1)
            {
                startGetStaff();
            }
            else
            {
                if(choise == 2)
                {
                    startAddStaff();
                }
                else
                {
                    if(choise == 3)
                    {
                        startDeleteStaff();
                    }
                    else
                    {
                        if(choise == 4)
                        {
                            startEditPerson();
                        }
                        else
                        {
                            exit = true;
                        }
                    }
                }
            }
        }
    }
    public int writeStaffMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** Staff Menu ***");
        System.out.println(" (1) Show information about a staff");
        System.out.println(" (2) Add staff");
        System.out.println(" (3) Delete staff");
        System.out.println(" (4) Update staff");
        System.out.println(" (5) Return");
        System.out.print("\n Make your choice: ");
        
        int choise = keyboard.nextInt();
        return choise;
    }
    private int editStaffData() 
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" (1) Edit first name");
        System.out.println(" (2) Edit last name");
        System.out.println(" (3) Edit address");
        System.out.println(" (4) Edit zipcode");
        System.out.println(" (5) Edit city");
        System.out.println(" (6) Edit phone number");
        System.out.println(" (7) Edit job posistion");
        int choise = keyboard.nextInt();
        return choise;
    }
    /**
     * User input section
     * 
     * inputFirstName(), inputs the persons Firstname via user interaction.
     * inputLastName(), inputs the persons LastName via user interaction.
     * inputzipCode(), inputs the persons postal code via user interaction.
     * inputCity(), inputs the persons city via user interaction.
     * inputPhone(), inputs the persons phone via user interaction.
     * inputAddress(), inputs the persons address via user interaction.
     * inputSalary(), inputs the persons salery via user interaction.
     * inputPosistion(), inputs the persons posistion via user interaction.
     */
     public String inputFirstName()
    {
         Scanner keyboard = new Scanner(System.in);  
         System.out.print(" Write firstname:  ");
         String firstName = keyboard.nextLine();
         return firstName;
    }
    public String inputLastName()
    {
         Scanner keyboard = new Scanner(System.in);  
         System.out.print(" Write lastname:  ");
         String lastName = keyboard.nextLine();
         return lastName;
    }
    public String inputAddress()
    {
         Scanner keyboard = new Scanner(System.in);  
         System.out.print(" Write address:  ");
         String address = keyboard.nextLine();
         return address;
    }
    public String inputZipCode()
    {
         Scanner keyboard = new Scanner(System.in);  
         System.out.print(" Write zipcode:  ");
         String zipcode = keyboard.nextLine();
         return zipcode;
    }
    public String inputCity()
    {
         Scanner keyboard = new Scanner(System.in);  
         System.out.print(" Write city:  ");
         String city = keyboard.nextLine();
         return city;
    }
    public String inputPhone()
    {
         Scanner keyboard = new Scanner(System.in);  
         System.out.print(" Write phoneNo:  ");
         String phoneNo = keyboard.nextLine();
         return phoneNo;
    }
    public double inputSalary()
    {
        Scanner keyboard = new Scanner(System.in);  
        System.out.print(" Write Salary:  ");
        double salary = keyboard.nextDouble();
        return salary;
    }
    public String inputPosistion()
    {
        Scanner keyboard = new Scanner(System.in);  
        System.out.print(" Write Job posistion:  ");
        String posistion = keyboard.nextLine();
        return posistion;
    }
    /**
    * User interaction section
     * 
     * startAddStaff(), creates a Staff in addressbook and stores it in array.
     * startGetStaff(), finds the Staff information trough there phonenumber via its perspectiv array.
     * startDeleteStaff(), deletes Staff if there phonenumber is found in array.
     * startEditStaff(), edits the Staff information after there phonenumber is found via there perspectiv arrays.
     * editStaffData(), is a visual interpretation of the Staff edit menu.
     */
    private void startAddStaff()
    {
        String firstName = inputFirstName();
        String lastName = inputLastName();
        String address = inputAddress();
        String zipcode = inputZipCode();
        String city = inputCity();
        String phoneNo = inputPhone();
        double salary = inputSalary();
        String posistion = inputPosistion();
        sctr.createStaff(firstName, lastName, address, zipcode, city, phoneNo, salary, posistion);
    }
    private void startGetStaff()
    {
        String phone = inputPhone();
        Staff staff = sctr.getStaff(phone);
        System.out.println("");
        System.out.println("### Staff information ###");
        System.out.println("Name: " + staff.getLastName() + ", " + staff.getFirstName());
        System.out.println("Address: " + staff.getAddress());
        System.out.println("Zip code: " + staff.getZipcode());
        System.out.println("City: " + staff.getCity());
        System.out.println("Phone number: " + staff.getPhoneNo());
        System.out.println("Salary: " + staff.getSalary());
        System.out.println("Position: " + staff.getPosition());
        
        pause();
    }
    private void startDeleteStaff() 
    {
        String phone = inputPhone();
        
        try
        {
            if(sctr.deleteStaff(phone))
            {
                System.out.println("\n **Staff deleted! **");
                Thread.sleep(1500);
            }
            else
            {
                System.out.println("\n ** No Staff with that phone number was found! **");
                Thread.sleep(1500);
            }
        }
        catch (Exception e)
        {
            System.out.println(" ** An error has occurred! **");
        }
    }
     private void startEditPerson() 
    {
        String phone = inputPhone();
        
        Staff staff = null;
        staff = sctr.getStaff(phone);
        
        try
        {
            if(staff != null)
            {
                int nr = editStaffData();
                Scanner keyboardData = new Scanner(System.in); 
                System.out.print(" Enter new data: ");
                String newData = keyboardData.nextLine();
                sctr.editStaffData(staff, nr, newData);
            }
            else
            {
                System.out.println("\n ** No person with that phone number was found! **");
                Thread.sleep(1500);
            }
        }
        catch (Exception e)
        {
            System.out.println(" ** An error has occurred! **");
        }
    }
    private void pause()
    {
        Scanner keyboard = new Scanner(System.in);
        String vent = keyboard.nextLine();
    }
    

   
   
}
